<template>
  <div>
    <el-card style="margin-top: 10px;">
      <div class="clearfix">
        <!-- 头部左侧内容 -->
        <el-tabs class="tab" v-model="activeName">
          <el-tab-pane label="销售额" name="sale"></el-tab-pane>
          <el-tab-pane label="访问量" name="visite"></el-tab-pane>
        </el-tabs>
        <!-- 头部右侧内容 -->
        <div class="right">
          <span @click="setDay">今日</span>
          <span @click="setWeek">本周</span>
          <span>本月</span>
          <span>本年</span>
          <el-date-picker
            class="date"
            v-model="date"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            size="mini">
          </el-date-picker>
        </div>
      </div>
      <div>
        <el-row>
          <el-col :span="18">
            <!-- 容器 -->
            <div class="charts" ref="charts"></div>
          </el-col>
          <el-col :span="6">
              <h3>门店{{title}}排名</h3>
              <ul>
                <li>
                  <span class="rindex">0</span>
                  <span style="padding: 0px 20px;">肯德基</span>
                  <span class="rvalue">133434</span>
                </li>
                <li>
                  <span class="rindex">1</span>
                  <span style="padding: 0px 20px;">肯德基</span>
                  <span class="rvalue">133434</span>
                </li>
                <li>
                  <span class="rindex">2</span>
                  <span style="padding: 0px 20px;">肯德基</span>
                  <span class="rvalue">133434</span>
                </li>
                <li>
                  <span>3</span>
                  <span style="padding: 0px 20px;">肯德基</span>
                  <span class="rvalue">133434</span>
                </li>
                <li>
                  <span>4</span>
                  <span style="padding: 0px 20px;">肯德基</span>
                  <span class="rvalue">133434</span>
                </li>
                <li>
                  <span>5</span>
                  <span style="padding: 0px 20px;">肯德基</span>
                  <span class="rvalue">133434</span>
                </li>
                <li>
                  <span>6</span>
                  <span style="padding: 0px 20px;">肯德基</span>
                  <span class="rvalue">133434</span>
                </li>
              </ul>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import dayjs from 'dayjs'
export default {
  name: '',
  data() {
    return {
      activeName:'sale',
      mycharts:null,
      // 收集日历数组
      date:[]
    };
  },
  mounted() {
      // 初始化echarts实例
      this.mycharts = echarts.init(this.$refs.charts)
      this.mycharts.setOption({
        title:{
          text: this.title + '趋势'
        },
        xAxis: {
          type: 'category',
          data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月','八月','九月','十月','十一月','十二月']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [120, 200, 150, 80, 70, 110, 130,55,10,13,99,100],
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)'
            }
          }
        ],
        grid:{
        left:0,
        
        right:0,
        bottom:0
      },
      })
    },
  computed:{
    // 计算属性-标题
    title(){
      return this.activeName=='sale'?'销售额':'访问量'
    }
  },
  watch:{
    title(){
      // 重新修改图表的配置数据
      this.mycharts.setOption({
        title:{
          text:this.title + '趋势'
        }
      })
    }
  },
  methods:{
    // 本天
    setDay(){
      const day = dayjs().format('YYYY-MM-DD')
      this.date = [day,day]
    },
    // 本周
    setWeek(){
      const start = dayjs().day(1).format('YYYY-MM-DD')
      const end = dayjs().day(7).format('YYYY-MM-DD')
      this.date = [start,end]
    }
  }
};
</script>

<style scoped>
.clearfix{
  position: relative;
  display: flex;
  justify-content: space-between;
}
.tab{
  width: 100%;
}
.right{
  position: absolute;
  right: 10px;
}
.right span{
  margin: 0px 10px;
}
.date{
  width: 240px;
  margin: 0px 20px;
}
.charts{
  width: 100%;
  height: 300px;
}
ul{
  list-style: none;
  width: 100%;
  height: 300px;
  padding: 0;
}
ul li{
  height: 8%;
  margin: 10px 0;
}
.rindex{
  float: left;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: black;
  color: white;
  text-align: center;
}
.rvalue{
  float: right;
}
</style>